<template>
	<view class="container">
		<view class="title">注册用户</view>
		<view class="tip">用户注册后才可以登录</view>
		<input placeholder="用户名" v-model="userName" class="input-username" />
		<input placeholder="密码" v-model="pwd" class="input-pwd" />
		<input placeholder="再输一次密码" v-model="pwd2" class="input-pwd2" />
		<view class="btn-regsiter" @click="regesiterUser">注册</view>
		<view @click="toLogin">已有账户、去登录</view>
	</view>
</template>

<script>
	import {
		httpPost
	} from '.././../api/httpUtils.js'
	import {
		registerUrl
	} from '../../api/constant.js'
	export default {
		data() {
			return {
				userName: '',
				pwd: '',
				pwd2: ''
			}
		},
		methods: {
			toLogin() {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			async regesiterUser() {
				let res = await httpPost(registerUrl, {
					username: this.userName,
					password: this.pwd,
					repassword: this.pwd2
				})
				console.log('注册返回' + res.errorMsg);
				let {
					errorCode,
					errorMsg
				} = res
				if (errorCode == 0) {
					uni.showToast({
						title: "注册成功"
					})
				} else {
					uni.showToast({
						title: errorMsg
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 32rpx;

		.btn-regsiter {
			background-color: green;
			text-align: center;
			color: white;
			font-size: 32rpx;
			padding: 12rpx;
			border-radius: 6rpx;
			margin-bottom: 12rpx;

		}

		input {
			margin: 16rpx 0 16rpx 0;
			padding: 5rpx;
		}

		.input-username {
			border: 1px solid green;
			border-radius: 6rpx;
		}

		.input-pwd {
			border: 1px solid green;
			border-radius: 6rpx;
		}

		.input-pwd2 {
			border: 1px solid green;
			border-radius: 6rpx;
		}

		.title {
			font-size: 32rpx;
			font-weight: 500;
			margin-bottom: 12rpx;
		}
	}
</style>
